if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

var Debugger = function () { };
Debugger.log = function (message) {
	try {
		console.log(message);
	} catch (exception) {
		return;
	}
}

function delegate( that, thatMethod ) {
	return function() { return thatMethod.call(that); }
}





function logObjectProperties(obj) {
	for(prop in obj) {
		Debugger.log(" value :" + prop + ":" +obj[prop]);
	}

}

function disableEnterKey(e)
{
  var key;
  
  if(window.event)
    key = window.event.keyCode;     //IE
  else
    key = e.which;     //firefox
  
  if(key == 13)
    return false;
  else
    return true;
}

function canvasSupport () {
  	return Modernizr.canvas;
}

function hitTest(image1,image2)  {
		r1left = image1.x;
		r1top  = image1.y;
		r1right = image1.x + image1.width;
		r1bottom = image1.y + image1.height;
		r2left = image2.x;
		r2top  = image2.y;
		r2right = image2.x + image2.width;
		r2bottom = image2.y + image2.height;
		retval = false;
		
		if ( (r1left > r2right) || (r1right < r2left) || (r1bottom < r2top) || (r1top > r2bottom) ) {
			retval = false;
		} else {
			retval = true;
		}
					 
		
		return retval;
	}
	
	

function splitTextIntoLines (text,textLineWidth,context) {
	var newLine ="";	
	var lastSpace = 0;
	var lastLineBreak = 0;
	var i = 0;
	var textLines = new Array();
	while (i < text.length) {
		if (text.charAt(i) == " " || text.charAt(i) == "\t") {
			lastSpace = i;
		}
		if (text.charAt(i) == "\n") {
			textLines.push(newLine);
			newLine = "";
			lastLineBreak = i;
			
		} else if ( context.measureText(newLine).width < textLineWidth ) {
				newLine += text.charAt(i);
				
		} else {
			if ( text.charAt(i) == " " || text.charAt(i) == "\t") {
				textLines.push(newLine);
				newLine = text.charAt(i);
				lastLineBreak = (i-1);
			} else {
				if (lastSpace > lastLineBreak) {
					newLineX = text.substring(lastLineBreak, lastSpace);
					textLines.push(newLineX);
					i = lastSpace;
					lastLineBreak = i;
					newLine = ""
				} else {
					textLines.push(newLine);
					newLine = text.charAt(i);
					lastLineBreak = (i-1);
				}
			}
				
		}
			
		i++;
	}
		
	if (newLine.length > 0) {
		textLines.push(newLine);
	}
	return textLines;	
}

